<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="./Css/common.css">
    <link rel="stylesheet" href="./Css/blog_list.css">
</head>
<body>
    <div class="nav">
        <img src="./image/西南石油大学.jpeg" alt="">
        <span>我的博客系统</span>
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="logout">注销</a>
    </div>
    <div class="container">
        <div class="left">
            <div class="card">
                <img src="./image/图片2.jpeg" alt="">
                <h3></h3>
                <a href="https://gitee.com/wen-junhao000">github地址</a>
                <div class="couter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="couter">
                    <span>1</span>
                    <span>2</span>
                </div>
            </div>
        </div>
        <div class="right">
            <!-- <div class="blog">
                <div class="title">我的第一篇博客</div>
                <div class="date">2020-11-28</div>
                <div class="desc">
                    从今天开始，我要认真学习Lorem ipsum dolor, sit amet consectetur adipisicing elit. Eligendi distinctio tempora dolore consequuntur! Quisquam voluptate cupiditate veniam quibusdam recusandae quod possimus culpa magni enim, corrupti vero illum omnis eaque voluptatibus.
                </div>
                <a href="blog_detail.html" class="detail">查看全文&gt;&gt;</a>
            </div> -->
            
        </div>
    </div>
    <script src="js/jquery.min.js"></script>
    <script>
        $.ajax({
            url:'blog',
            method:'GET',
            success:function(data,status){
                buildBlogs(data);
            },
            error:function(data,status){
                location.assign('login.html');
            }
        })
        function buildBlogs(blogs){
            // let rightDiv=document.createElement('div');
            // rightDiv.className='right';
            let rightDiv=document.querySelector('.container .right');
            for(let blog of blogs){
                let blogDiv=document.createElement('div');
                blogDiv.className='blog';
                let titleDiv=document.createElement('div');
                titleDiv.className='title';
                titleDiv.innerHTML=blog.title;
                blogDiv.appendChild(titleDiv);
                let dateDiv=document.createElement('div');
                dateDiv.className='date';
                dateDiv.innerHTML=formatDate(blog.postTime);
                blogDiv.appendChild(dateDiv);
                let descDiv=document.createElement('div');
                descDiv.className='desc';
                descDiv.innerHTML=blog.content;
                blogDiv.appendChild(descDiv);
                let detailA=document.createElement('a');
                detailA.className='detail';
                detailA.innerHTML='查看全文 &gt; &gt;';
                detailA.href='blog_detail.html?blogId='+blog.blogId;
                blogDiv.appendChild(detailA);
                rightDiv.appendChild(blogDiv);
            }
        }
    function formatDate(timeStampMS){
        var date = new Date(timeStampMS);

	var year = date.getFullYear(),
		month = date.getMonth()+1,//月份是从0开始的
		day = date.getDate(),
		hour = date.getHours(),
		min = date.getMinutes(),
		sec = date.getSeconds();
	var newTime = year + '-' +
				(month < 10? '0' + month : month) + '-' +
				(day < 10? '0' + day : day) + ' ' +
				(hour < 10? '0' + hour : hour) + ':' +
				(min < 10? '0' + min : min) + ':' +
				(sec < 10? '0' + sec : sec);

	return newTime;
    }
    $.ajax({
        method:'GET',
        url:'user',
        success:function(data,status){
            changUser(data);
        }
    })
    function changUser(user){
        let h3=document.querySelector('.card>h3');
        h3.innerHTML=user.username;

    }
    </script>
</body>
</html>